package com.rocksdata.mc.database;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;

import com.ctz.commonframe.utils.DateUtil;
import com.ctz.commonframe.utils.Logger;
import com.rocksdata.mc.entity.AnnouncementInfo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by 陈堂正 on 2017/4/28.
 */

public class AnnouncementDBManager {
    private static final String TAG = "AnnouncementDBManager";
    private static AnnouncementDBManager instance;

    private AnnouncementDBManager(){

    }

    static synchronized AnnouncementDBManager getInstance(){
        if(instance == null){
            instance = new AnnouncementDBManager();
        }
        return instance;
    }

    public void setRead(String id){
        ContentValues values = new ContentValues();
        values.put(DatabaseHelper.TAnnouncementInfo.ANNOUNCEMENT_ID, id);
        values.put(DatabaseHelper.TAnnouncementInfo.READ_STATUS, AnnouncementInfo.IS_READ);
        DatabaseManager.getDatabase().replace(DatabaseHelper.TAnnouncementInfo.TABLE_NAME, null, values);
    }

    public boolean isRead(String id) {
        if (TextUtils.isEmpty(id))
            return false;
        Cursor c = DatabaseManager.getDatabase().query(DatabaseHelper.TAnnouncementInfo.TABLE_NAME, null,
                DatabaseHelper.TAnnouncementInfo.ANNOUNCEMENT_ID + "=?",
                new String[]{id}, null, null, null);
        if (c.moveToFirst()) {
            int readStatus = c.getInt(c.getColumnIndex(DatabaseHelper.TAnnouncementInfo.READ_STATUS));
            return readStatus == AnnouncementInfo.IS_READ;
        }
        return false;
    }
}
